/*
 * Copyright (c) 2021 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include "movement_module_test.h"

#include <iostream>
#include <chrono>
#include <thread>
#include <gtest/gtest.h>
#include <if_system_ability_manager.h>
#include <ipc_skeleton.h>
#include <string_ex.h>

#include "movement_common.h"
#include "movement_client.h"

using namespace testing::ext;
using namespace OHOS::Msdp;
using namespace OHOS;
using namespace std;

void MovementModuleTest::MovementTestCallback::OnMovementChanged(const MovementDataUtils::MovementData& movementData)
{
    MOVEMENT_HILOGI(MOVEMENT_MODULE_SERVICE, "Enter");
    GTEST_LOG_(INFO) << "MovementTestCallback type: " << movementData.type;
    GTEST_LOG_(INFO) << "MovementTestCallback value: " << movementData.value;
    EXPECT_EQ(true, movementData.type == MovementDataUtils::MovementType::TYPE_IN_VEHICLE &&
        movementData.value == MovementDataUtils::MovementValue::VALUE_ENTER) << "MovementTestCallback falied";
    MOVEMENT_HILOGI(MOVEMENT_MODULE_SERVICE, "Exit");
}

/**
 * @tc.name: MovementModuleTest001
 * @tc.desc: Test movement callback in proxy
 * @tc.type: FUNC
 */
HWTEST_F (MovementModuleTest, MovementModuleTest001, TestSize.Level0)
{
    MOVEMENT_HILOGI(MOVEMENT_MODULE_SERVICE, "MovementModuleTest001 Enter");
    MovementDataUtils::MovementType type = MovementDataUtils::MovementType::TYPE_IN_VEHICLE;
    auto& movementClient = MovementClient::GetInstance();
    sptr<ImovementCallback> cb = new MovementTestCallback();
    GTEST_LOG_(INFO) << "Start register";
    movementClient.SubscribeCallback(type, cb);
    GTEST_LOG_(INFO) << "Cancel register";
    movementClient.UnSubscribeCallback(type, cb);
    MOVEMENT_HILOGI(MOVEMENT_MODULE_SERVICE, "Exit");
}

/**
 * @tc.name: MovementModuleTest002
 * @tc.desc: Test movement callback in proxy
 * @tc.type: FUNC
 */
HWTEST_F (MovementModuleTest, MovementModuleTest002, TestSize.Level0)
{
    MOVEMENT_HILOGI(MOVEMENT_MODULE_SERVICE, "MovementModuleTest002 Enter");
    MovementDataUtils::MovementType type = MovementDataUtils::MovementType::TYPE_IN_AUTO;
    auto& movementClient = MovementClient::GetInstance();
    sptr<ImovementCallback> cb = new MovementTestCallback();
    GTEST_LOG_(INFO) << "Start register";
    movementClient.SubscribeCallback(type, cb);
    GTEST_LOG_(INFO) << "Cancel register";
    movementClient.UnSubscribeCallback(type, cb);
    MOVEMENT_HILOGI(MOVEMENT_MODULE_SERVICE, "Exit");
}

/**
 * @tc.name: MovementModuleTest003
 * @tc.desc: Test movement callback in proxy
 * @tc.type: FUNC
 */
HWTEST_F (MovementModuleTest, MovementModuleTest003, TestSize.Level0)
{
    MOVEMENT_HILOGI(MOVEMENT_MODULE_SERVICE, "MovementModuleTest003 Enter");
    MovementDataUtils::MovementType type = MovementDataUtils::MovementType::TYPE_IN_PLANE;
    auto& movementClient = MovementClient::GetInstance();
    sptr<ImovementCallback> cb = new MovementTestCallback();
    GTEST_LOG_(INFO) << "Start register";
    movementClient.SubscribeCallback(type, cb);
    GTEST_LOG_(INFO) << "Cancel register";
    movementClient.UnSubscribeCallback(type, cb);
    MOVEMENT_HILOGI(MOVEMENT_MODULE_SERVICE, "Exit");
}

/**
 * @tc.name: MovementModuleTest004
 * @tc.desc: Test movement callback in proxy
 * @tc.type: FUNC
 */
HWTEST_F (MovementModuleTest, MovementModuleTest004, TestSize.Level0)
{
    MOVEMENT_HILOGI(MOVEMENT_MODULE_SERVICE, "MovementModuleTest004 Enter");
    MovementDataUtils::MovementType type = MovementDataUtils::MovementType::TYPE_IN_METRO;
    auto& movementClient = MovementClient::GetInstance();
    sptr<ImovementCallback> cb = new MovementTestCallback();
    GTEST_LOG_(INFO) << "Start register";
    movementClient.SubscribeCallback(type, cb);
    GTEST_LOG_(INFO) << "Cancel register";
    movementClient.UnSubscribeCallback(type, cb);
    MOVEMENT_HILOGI(MOVEMENT_MODULE_SERVICE, "Exit");
}

/**
 * @tc.name: MovementModuleTest005
 * @tc.desc: Test movement callback in proxy
 * @tc.type: FUNC
 */
HWTEST_F (MovementModuleTest, MovementModuleTest005, TestSize.Level0)
{
    MOVEMENT_HILOGI(MOVEMENT_MODULE_SERVICE, "MovementModuleTest005 Enter");
    MovementDataUtils::MovementType type = MovementDataUtils::MovementType::TYPE_IN_ELEVATOR;
    auto& movementClient = MovementClient::GetInstance();
    sptr<ImovementCallback> cb = new MovementTestCallback();
    GTEST_LOG_(INFO) << "Start register";
    movementClient.SubscribeCallback(type, cb);
    GTEST_LOG_(INFO) << "Cancel register";
    movementClient.UnSubscribeCallback(type, cb);
    MOVEMENT_HILOGI(MOVEMENT_MODULE_SERVICE, "Exit");
}

/**
 * @tc.name: MovementModuleTest006
 * @tc.desc: Test movement callback in proxy
 * @tc.type: FUNC
 */
HWTEST_F (MovementModuleTest, MovementModuleTest006, TestSize.Level0)
{
    MOVEMENT_HILOGI(MOVEMENT_MODULE_SERVICE, "MovementModuleTest006 Enter");
    MovementDataUtils::MovementType type = MovementDataUtils::MovementType::TYPE_ON_BICYCLE;
    auto& movementClient = MovementClient::GetInstance();
    sptr<ImovementCallback> cb = new MovementTestCallback();
    GTEST_LOG_(INFO) << "Start register";
    movementClient.SubscribeCallback(type, cb);
    GTEST_LOG_(INFO) << "Cancel register";
    movementClient.UnSubscribeCallback(type, cb);
    MOVEMENT_HILOGI(MOVEMENT_MODULE_SERVICE, "Exit");
}

/**
 * @tc.name: MovementModuleTest007
 * @tc.desc: Test movement callback in proxy
 * @tc.type: FUNC
 */
HWTEST_F (MovementModuleTest, MovementModuleTest007, TestSize.Level0)
{
    MOVEMENT_HILOGI(MOVEMENT_MODULE_SERVICE, "MovementModuleTest007 Enter");
    MovementDataUtils::MovementType type = MovementDataUtils::MovementType::TYPE_STAY;
    auto& movementClient = MovementClient::GetInstance();
    sptr<ImovementCallback> cb = new MovementTestCallback();
    GTEST_LOG_(INFO) << "Start register";
    movementClient.SubscribeCallback(type, cb);
    GTEST_LOG_(INFO) << "Cancel register";
    movementClient.UnSubscribeCallback(type, cb);
    MOVEMENT_HILOGI(MOVEMENT_MODULE_SERVICE, "Exit");
}

/**
 * @tc.name: MovementModuleTest008
 * @tc.desc: Test movement callback in proxy
 * @tc.type: FUNC
 */
HWTEST_F (MovementModuleTest, MovementModuleTest008, TestSize.Level0)
{
    MOVEMENT_HILOGI(MOVEMENT_MODULE_SERVICE, "MovementModuleTest008 Enter");
    MovementDataUtils::MovementType type = MovementDataUtils::MovementType::TYPE_STILL;
    auto& movementClient = MovementClient::GetInstance();
    sptr<ImovementCallback> cb = new MovementTestCallback();
    GTEST_LOG_(INFO) << "Start register";
    movementClient.SubscribeCallback(type, cb);
    GTEST_LOG_(INFO) << "Cancel register";
    movementClient.UnSubscribeCallback(type, cb);
    MOVEMENT_HILOGI(MOVEMENT_MODULE_SERVICE, "Exit");
}

/**
 * @tc.name: MovementModuleTest009
 * @tc.desc: Test movement callback in proxy
 * @tc.type: FUNC
 */
HWTEST_F (MovementModuleTest, MovementModuleTest009, TestSize.Level0)
{
    MOVEMENT_HILOGI(MOVEMENT_MODULE_SERVICE, "MovementModuleTest009 Enter");
    MovementDataUtils::MovementType type = MovementDataUtils::MovementType::TYPE_RELATIVE_STILL;
    auto& movementClient = MovementClient::GetInstance();
    sptr<ImovementCallback> cb = new MovementTestCallback();
    GTEST_LOG_(INFO) << "Start register";
    movementClient.SubscribeCallback(type, cb);
    GTEST_LOG_(INFO) << "Cancel register";
    movementClient.UnSubscribeCallback(type, cb);
    MOVEMENT_HILOGI(MOVEMENT_MODULE_SERVICE, "Exit");
}

/**
 * @tc.name: MovementModuleTest010
 * @tc.desc: Test movement callback in proxy
 * @tc.type: FUNC
 */
HWTEST_F (MovementModuleTest, MovementModuleTest010, TestSize.Level0)
{
    MOVEMENT_HILOGI(MOVEMENT_MODULE_SERVICE, "MovementModuleTest010 Enter");
    MovementDataUtils::MovementType type = MovementDataUtils::MovementType::TYPE_ON_FOOT;
    auto& movementClient = MovementClient::GetInstance();
    sptr<ImovementCallback> cb = new MovementTestCallback();
    GTEST_LOG_(INFO) << "Start register";
    movementClient.SubscribeCallback(type, cb);
    GTEST_LOG_(INFO) << "Cancel register";
    movementClient.UnSubscribeCallback(type, cb);
    MOVEMENT_HILOGI(MOVEMENT_MODULE_SERVICE, "Exit");
}

/**
 * @tc.name: MovementModuleTest011
 * @tc.desc: Test movement callback in proxy
 * @tc.type: FUNC
 */
HWTEST_F (MovementModuleTest, MovementModuleTest011, TestSize.Level0)
{
    MOVEMENT_HILOGI(MOVEMENT_MODULE_SERVICE, "MovementModuleTest011 Enter");
    MovementDataUtils::MovementType type = MovementDataUtils::MovementType::TYPE_WALKING;
    auto& movementClient = MovementClient::GetInstance();
    sptr<ImovementCallback> cb = new MovementTestCallback();
    GTEST_LOG_(INFO) << "Start register";
    movementClient.SubscribeCallback(type, cb);
    GTEST_LOG_(INFO) << "Cancel register";
    movementClient.UnSubscribeCallback(type, cb);
    MOVEMENT_HILOGI(MOVEMENT_MODULE_SERVICE, "Exit");
}

/**
 * @tc.name: MovementModuleTest012
 * @tc.desc: Test movement callback in proxy
 * @tc.type: FUNC
 */
HWTEST_F (MovementModuleTest, MovementModuleTest012, TestSize.Level0)
{
    MOVEMENT_HILOGI(MOVEMENT_MODULE_SERVICE, "MovementModuleTest012 Enter");
    MovementDataUtils::MovementType type = MovementDataUtils::MovementType::TYPE_WALKING_HANDHOLD;
    auto& movementClient = MovementClient::GetInstance();
    sptr<ImovementCallback> cb = new MovementTestCallback();
    GTEST_LOG_(INFO) << "Start register";
    movementClient.SubscribeCallback(type, cb);
    GTEST_LOG_(INFO) << "Cancel register";
    movementClient.UnSubscribeCallback(type, cb);
    MOVEMENT_HILOGI(MOVEMENT_MODULE_SERVICE, "Exit");
}

/**
 * @tc.name: MovementModuleTest013
 * @tc.desc: Test movement callback in proxy
 * @tc.type: FUNC
 */
HWTEST_F (MovementModuleTest, MovementModuleTest013, TestSize.Level0)
{
    MOVEMENT_HILOGI(MOVEMENT_MODULE_SERVICE, "MovementModuleTest013 Enter");
    MovementDataUtils::MovementType type = MovementDataUtils::MovementType::TYPE_FAST_WALKING;
    auto& movementClient = MovementClient::GetInstance();
    sptr<ImovementCallback> cb = new MovementTestCallback();
    GTEST_LOG_(INFO) << "Start register";
    movementClient.SubscribeCallback(type, cb);
    GTEST_LOG_(INFO) << "Cancel register";
    movementClient.UnSubscribeCallback(type, cb);
    MOVEMENT_HILOGI(MOVEMENT_MODULE_SERVICE, "Exit");
}

/**
 * @tc.name: MovementModuleTest014
 * @tc.desc: Test movement callback in proxy
 * @tc.type: FUNC
 */
HWTEST_F (MovementModuleTest, MovementModuleTest014, TestSize.Level0)
{
    MOVEMENT_HILOGI(MOVEMENT_MODULE_SERVICE, "MovementModuleTest014 Enter");
    MovementDataUtils::MovementType type = MovementDataUtils::MovementType::TYPE_RUNNING;
    auto& movementClient = MovementClient::GetInstance();
    sptr<ImovementCallback> cb = new MovementTestCallback();
    GTEST_LOG_(INFO) << "Start register";
    movementClient.SubscribeCallback(type, cb);
    GTEST_LOG_(INFO) << "Cancel register";
    movementClient.UnSubscribeCallback(type, cb);
    MOVEMENT_HILOGI(MOVEMENT_MODULE_SERVICE, "Exit");
}

/**
 * @tc.name: MovementModuleTest015
 * @tc.desc: Test movement callback in proxy
 * @tc.type: FUNC
 */
HWTEST_F (MovementModuleTest, MovementModuleTest015, TestSize.Level0)
{
    MOVEMENT_HILOGI(MOVEMENT_MODULE_SERVICE, "MovementModuleTest015 Enter");
    MovementDataUtils::MovementType type = MovementDataUtils::MovementType::TYPE_LYING_POSTURE;
    auto& movementClient = MovementClient::GetInstance();
    sptr<ImovementCallback> cb = new MovementTestCallback();
    GTEST_LOG_(INFO) << "Start register";
    movementClient.SubscribeCallback(type, cb);
    GTEST_LOG_(INFO) << "Cancel register";
    movementClient.UnSubscribeCallback(type, cb);
    MOVEMENT_HILOGI(MOVEMENT_MODULE_SERVICE, "Exit");
}

/**
 * @tc.name: MovementModuleTest016
 * @tc.desc: Test movement callback in proxy
 * @tc.type: FUNC
 */
HWTEST_F (MovementModuleTest, MovementModuleTest016, TestSize.Level0)
{
    MOVEMENT_HILOGI(MOVEMENT_MODULE_SERVICE, "MovementModuleTest016 Enter");
    MovementDataUtils::MovementType type = MovementDataUtils::MovementType::TYPE_SMART_FLIGHT;
    auto& movementClient = MovementClient::GetInstance();
    sptr<ImovementCallback> cb = new MovementTestCallback();
    GTEST_LOG_(INFO) << "Start register";
    movementClient.SubscribeCallback(type, cb);
    GTEST_LOG_(INFO) << "Cancel register";
    movementClient.UnSubscribeCallback(type, cb);
    MOVEMENT_HILOGI(MOVEMENT_MODULE_SERVICE, "Exit");
}

/**
 * @tc.name: MovementModuleTest017
 * @tc.desc: Test movement callback in proxy
 * @tc.type: FUNC
 */
HWTEST_F (MovementModuleTest, MovementModuleTest017, TestSize.Level0)
{
    MOVEMENT_HILOGI(MOVEMENT_MODULE_SERVICE, "MovementModuleTest017 Enter");
    MovementDataUtils::MovementType type = MovementDataUtils::MovementType::TYPE_HIGH_SPEED_RAIL;
    auto& movementClient = MovementClient::GetInstance();
    sptr<ImovementCallback> cb = new MovementTestCallback();
    GTEST_LOG_(INFO) << "Start register";
    movementClient.SubscribeCallback(type, cb);
    GTEST_LOG_(INFO) << "Cancel register";
    movementClient.UnSubscribeCallback(type, cb);
    MOVEMENT_HILOGI(MOVEMENT_MODULE_SERVICE, "Exit");
}
